/*
 * EditLinkProvisionsDialog.java
 *
 * Created on September 11, 2007, 10:24 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.gui.dialogs;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.fpdev.apps.rtemaster.RouteMaster;
import org.fpdev.util.gui.GUIFactory;
import org.fpdev.apps.rtemaster.gui.LinkOptionsPanel;

/**
 *
 * @author demory
 */
public class EditLinkProvisionsDialog extends JDialog implements ActionListener {

  private JComboBox bikePed_;
  private JButton okBtn_,  cancelBtn_;
  private boolean okPressed_;

  /** Creates a new instance of EditLinkProvisionsDialog */
  public EditLinkProvisionsDialog(RouteMaster av) {
    super(av.getGUI(), "Link Provisions", true);

    bikePed_ = LinkOptionsPanel.createBikeProvisionsComboBox();

    okBtn_ = new JButton("OK");
    okBtn_.addActionListener(this);
    cancelBtn_ = new JButton("Cancel");
    cancelBtn_.addActionListener(this);

    JPanel btnRow = new JPanel();
    btnRow.setLayout(new BoxLayout(btnRow, BoxLayout.X_AXIS));
    btnRow.add(Box.createHorizontalGlue());
    btnRow.add(okBtn_);
    btnRow.add(Box.createHorizontalStrut(5));
    btnRow.add(cancelBtn_);
    btnRow.add(Box.createHorizontalGlue());

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    JLabel label = GUIFactory.newLabel("Link Type:");
    label.setAlignmentX(LEFT_ALIGNMENT);
    mainPanel.add(label);
    mainPanel.add(Box.createVerticalStrut(5));
    bikePed_.setAlignmentX(LEFT_ALIGNMENT);
    mainPanel.add(bikePed_);
    mainPanel.add(Box.createVerticalStrut(6));
    btnRow.setAlignmentX(LEFT_ALIGNMENT);
    mainPanel.add(btnRow);

    mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(mainPanel);

    this.pack();
    this.setLocation((av.getGUI().getWidth() / 2) - getWidth() / 2 + av.getGUI().getX(),
            (av.getGUI().getHeight() / 2) - getHeight() / 2 + av.getGUI().getY());
    this.setVisible(true);

  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == okBtn_) {
      okPressed_ = true;
      this.setVisible(false);
    } else if (e.getSource() == cancelBtn_) {
      this.setVisible(false);
    }
  }

  public boolean okPressed() {
    return okPressed_;
  }

  public int getBikePedType() {
    return Integer.parseInt(((String) bikePed_.getSelectedItem()).split("\\.")[0]);
  }
}
